package com.fastjpa.controller;

import java.util.List;

import com.fastjpa.vo.SaveStudentVo;
import org.springframework.web.bind.annotation.*;
import com.fastjpa.vo.StudentVo;
import com.fastjpa.service.StudentService;
import com.fastjpa.ResponseData;
import com.efeichong.common.PageData;
import lombok.RequiredArgsConstructor;

/**
* @author admin
* @date 2022/07/17
* @description 学生
*/
@RestController
@RequestMapping("/student")
@RequiredArgsConstructor
public class StudentController {

    private final StudentService studentService;

    @GetMapping(value = "/getInfo")
    public ResponseData<StudentVo> getInfo(@RequestParam("id") Long id) {
        return new ResponseData(studentService.getInfo(id));
    }

    @GetMapping("/page")
    public ResponseData<PageData<StudentVo>> page(StudentVo studentVo) {
        return new ResponseData(studentService.selectByPage(studentVo));
    }

    @PostMapping("insert")
    public ResponseData insert(@RequestBody SaveStudentVo studentVo) {
        studentService.insertStudent(studentVo);
        return new ResponseData();
    }

    @PostMapping("update")
    public ResponseData update(@RequestBody SaveStudentVo studentVo) {
        studentService.updateStudent(studentVo);
        return new ResponseData();
    }

    @GetMapping("/deleteByIds")
    public ResponseData deleteStudentByIds(@RequestParam("ids") List<Long> ids) {
        studentService.deleteByIds(ids);
        return new ResponseData();
    }

    @GetMapping("/deleteById")
    public ResponseData deleteStudentById(@RequestParam("id") Long id) {
        studentService.deleteById(id);
        return new ResponseData();
    }

}
